// pages/orderInfo/orderInfo.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    refreshed: true, // 将本属性设置为true，收起下拉刷新，可多次设置为true（即便原来已经是true了）
    skeleton: true, // 骨架屏
    eqid: 0,
    bottomLoad: false,
    disableBottomLoad: false,
    infoData: {},
    infoList: [
      {label: '设备名称', prop: 'eqName', event: 'viewInfo'},
      {label: '设备编号', prop: 'eqNumber'},
      {label: '开始时间', prop: 'startDate'},
      {label: '结束时间', prop: 'endDate'},
      {label: '发起人', prop: 'user'},
      {label: '发起时间', prop: 'openDate'},
      {label: '备注', prop: 'remake'},
      {label: '经纬度', prop: 'latitude'},
      {label: '地点', prop: 'site', icon: 'location', event:'openSite'},
    ],
    record: [{
      title: '测试记录1',
      content: '测试描述',
      time: '2021-08-20 18:15:11',
      subtitle: '审核'
    },{
      title: '测试记录1',
      time: '2021-08-20 18:15:11',
      content: '测试描述',
      subtitle: '审核'
    },]
  },

  onLoad: function ({id}) {
    console.log('设备id：', id);
    this.setData({
      eqid: +id,
    }, this.refresh());
  },
  colEvent(e) {
    if(e.target.dataset.event) {
      this[e.target.dataset.event]();
    }
  },
  // 查看设备详情
  viewInfo() {
    wx.navigateTo({
      url: '../equipmentInfo/equipmentInfo',
    })
  },
  // 打开地址
  openSite() {
    let {infoData} = this.data;
    let [longitude, latitude] = infoData.latitude.split(',').map(v => +v);
    wx.openLocation({
      latitude,
      longitude,
      name: infoData.site
    })
  },
  refresh() {
    this.setData({
      skeleton: true
    });
    this.getData();
  },
  // 请求数据接口
  getData() {
    let infoData = {
      eqName: '测试设备1',
      eqNumber: '0001',
      startDate: '2021-08-01',
      endDate: '2021-10-01',
      user: '超管',
      openDate: '2021-08-30',
      remake: '测试备注',
      latitude: '116.344651,40.020225',
      site: '上海市普陀区曹杨新村街道鸿运大厦上海鸿运大厦(武宁路)'
    };
    setTimeout(() => {
      this.setData({
        infoData,
        disableBottomLoad: true,
        bottomLoad: false,
        skeleton: false,
        refreshed: true,
      });
    }, 1000)
  },
})